/**
 * @description 评论实体
 * @author LI
 * @date 2020-11-11 16:03
 */

import {
  Column,
  CreateDateColumn,
  Entity, JoinColumn,
  ManyToOne, OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn
} from 'typeorm'
import { ArticleEntity } from '../article/article.entity'
import { UserEntity } from '../user/user.entity'

@Entity('li_comments')
export class CommentEntity {
  @PrimaryGeneratedColumn({ comment: '主键id' })
  id: number

  @ManyToOne(() => UserEntity, user => user.comments)
  @JoinColumn({ name: 'user_id' })
  userId: UserEntity

  @Column({ type: 'text', nullable: true, comment: '评论内容' })
  content: string

  @CreateDateColumn()
  @Column({ type: 'datetime', name: 'created_at', comment: '创建时间' })
  createdAt: Date

  @CreateDateColumn()
  @UpdateDateColumn()
  @Column({ type: 'datetime', name: 'updated_at', comment: '更新时间' })
  updatedAt: Date

  @ManyToOne(() => ArticleEntity, article => article.comments)
  @JoinColumn({ name: 'article_id' })
  articleId: ArticleEntity

  @ManyToOne(() => CommentEntity, comment => comment.parentComments)
  @JoinColumn({ name: 'parent_comment_id' })
  parentCommentId: CommentEntity

  @OneToMany(() => CommentEntity, comment => comment.parentCommentId)
  parentComments: CommentEntity[]
}